package com.jsz.yun.ai.field.entity;

import cn.hutool.core.util.ObjUtil;
import lombok.Builder;
import lombok.Data;

import java.util.Date;
import java.util.regex.Pattern;

/**
 * @author gaoxing
 * @date 2025-03-24 21:33:05
 */
@Data
@Builder
public class UserEntity {

    private String userId;

    private String phoneNumber;

    private String password;

    private String promotionCode;

    private Date createTime;

    private Date updateTime;

    private String userName;

    private String traceId;

    private String token;

    private Long diskSize;

    public static UserEntity saveCommon(String phoneNumber, String traceId, String password,
                                        String promotionCode) {
        if (!isValidPhoneNumber(phoneNumber)) {
            throw new IllegalArgumentException("手机号格式不合法，必须为中国大陆手机号");
        }
        return UserEntity.builder().phoneNumber(phoneNumber).password(password).promotionCode(promotionCode).traceId(traceId).build();
    }

    private static boolean isValidPhoneNumber(String phoneNumber) {
        if (ObjUtil.isEmpty(phoneNumber)) {
            return false;
        }
        // 正则表达式：手机号为11位数字
        String regex = "^1[3-9]\\d{9}$";
        return Pattern.matches(regex, phoneNumber);
    }
}
